cc.Class({
  extends: cc.Component,

  properties: {},

  onLoad: function() {
    this.node.group = 'paddle'; //给预制体分组

    this.node.parent.on('touchmove', event => {
      //将世界坐标转化为本地坐标
      let touchPoint = this.node.parent.convertToNodeSpace(event.getLocation());
      // console.log(touchPoint);
      let windowSize = cc.winSize; //推荐  原因  短
      let { width, height } = this.node;

      if (touchPoint.x >= windowSize.width - width / 2) {
        touchPoint.x = windowSize.width - width / 2;
      }
      if (touchPoint.x <= width / 2) {
        touchPoint.x = width / 2;
      }

      this.node.x = touchPoint.x;

      // let windowSize = cc.view.getVisibleSize();
      // console.log('width=' + windowSize.width + ',height=' + windowSize.height);
      // windowSize = cc.winSize; //推荐  原因  短
      // console.log('width=' + windowSize.width + ',height=' + windowSize.height);
    });
  },

  init(gameCtl) {
    // console.log('初始化')
    // console.log(this.node)
    this.gameCtl = gameCtl;
    this.node.height = 80;
    this.node.width = 300;
    this.node.scaleX = 1;
    this.node.scaleY = 1;
    this.node.x = 540;
  },

  // 物体碰撞到平板
  onBeginContact(contact, self, other) {
    if (other.node.brick_type && this.gameCtl.gameModel.isGame) {
      other.node.destroy();
      if (other.node.brick_type === 1) {
        // 弹射球
        this.gameCtl.onAddBallNFC(2);
      }
      if (other.node.brick_type === 2) {
        // 加宽滑板
        this.onWidePaddle();
      }
    }
  },

  onWidePaddle() {
    this.node.scaleX += 0.05;
    this.node.scaleY += 0.05;
  }

  // onAddBallNFC() {
  //   let ball_NPC = cc.instantiate(this.ball_NPC_Prefab);
  //   console.log(ball_NPC);
  //   // brickNode.parent = this.node;
  // }
});
